//
//  NcitBleDevice.h
//  BleHrateDemo
//
//  Created by Yongfeng Li on 8/15/14.
//  Copyright (c) 2014 Yongfeng Li. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

@protocol NcitBLeDevDelegate <NSObject>


@optional
- (void) recvedBleWgtData:(double)dWgt fat:(float)fFat wat:(float)fWat mus:(float)fMus bone:(float)fBone wUnit:(short)nUn fatwatInc:(BOOL)bFatWat hgt:(float)fHgt;
- (void) recvedBleOthData:(NSString*) data;
//- (void) recvedBleWgtData: (NSData *)data;

- (void) sendDataToBLeDev:(CBCharacteristic*)aChar;
- (void) sendDataToYunmaiBLeDev:(CBCharacteristic*)aChar;

- (void) recvedHrateData: (short)nHrate;
- (void) bleSupport:(BOOL)bSupport;

- (void) beginMeasBldPre;
- (void) updateBldPreVal:(short)nPresVal;
- (void) recvedBldPreVal:(Byte)nhPres lPres: (Byte)nlPres hRate:(Byte)nhRate;

- (void) updateBatteryLevel:(short)nLevel;
- (void) bleMgrDiscover:(CBPeripheral *)aPeripheral;

- (void) bleDevConnected;
- (void) bleDisconnected;

- (void) bleDiscoverFailed;
- (void) onBLeDevDiscoverTimeOut;

@end

@interface NcitBleDevice : NSObject<CBCentralManagerDelegate, CBPeripheralDelegate>

@property (assign, nonatomic) BOOL bAutoConnect;
@property (strong) id<NcitBLeDevDelegate> bleDelegate;
@property (strong) CBPeripheral*       pBleDevSvr;
@property (strong) CBCharacteristic*   pBleDevChar;
@property (assign, nonatomic) BOOL bConnBleDev;

- (id) initBleDevice;

- (void) startMeas:(NSString*)sBleUUID;
- (void) stopMeas;
- (void) stopScan;

- (void) sendDataToBLeDev:(CBCharacteristic*)aChar data:(NSData*) valData type:(CBCharacteristicWriteType)hdType;

- (NSUInteger) connBLEDevCount;
- (CBPeripheral*) listBleDev:(NSInteger)nIdx;
- (void) retrievePeripherals:(NSArray *)peripheralUUIDs;
- (void) cancelPeripheralConnection/*:(CBPeripheral *)peripheral*/;

@end
